//
//  CashRuleViewController.m
//  日日顺家居
//
//  Created by 堂堂 on 17/2/14.
//  Copyright © 2017年 堂堂. All rights reserved.
//

#import "CashRuleViewController.h"
#import "UIColor+Hex.h"
#import "UserDefaultUtil.h"
#import "MBProgressHUD+MJ.h"
#import "UserDefaultUtil.h"
#import "HttpReauestParam.h"
#import "AFHTTPRequestOperationManager.h"

#define ScreenHeight [[UIScreen mainScreen] bounds].size.height//获取屏幕高度，兼容性测试
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width//获取屏幕宽度，兼容性测试
@interface CashRuleViewController ()

@end

@implementation CashRuleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)setTheView:(NSArray *) array{


    int height = 30;
    int padingLeft = 30;
    for (int i = 0; i < array.count; i++) {
        UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(padingLeft, height, ScreenWidth - padingLeft, 30)];
        NSString *str = [NSString stringWithFormat:@"%@",array[i]];
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
         [paragraphStyle setLineSpacing:3];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [str length])];
        
        lab.attributedText = attributedString;
        [_contentView addSubview:lab];
        
        [lab sizeToFit];
        height = height + lab.frame.size.height;
    }
}

-(void)getAmountData{
    
    NSString *userId = [UserDefaultUtil getUserId];
    NSDictionary *dic =@{@"identifier":userId};
    
    HttpReauestParam *param = [[HttpReauestParam alloc]initWithData:@"wallet_statistics" content:[self dictionaryToJson:dic] urlType:0];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:param.SEVICE_URL parameters:param.param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary * data = [NSJSONSerialization JSONObjectWithData:operation.responseObject options:0 error:nil];
        
        if ([data[@"success"] boolValue]) {
            
            NSArray *array = data[@"result"];
            
            [self setTheView:array];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    }];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)back_click:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSString*)dictionaryToJson:(NSDictionary *)dic

{
    
    NSError *parseError = nil;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
}

@end
